<?php
session_start();
if (isset($_SESSION["username"])) {
?>
  <?php require_once('common/header.php'); ?>
  <!--页面主要内容-->
  <main class="lyear-layout-content">
    <div class="container-fluid">
      <div class="row">
        <div class="col-lg-12">
          <div class="card">
            <div class="card-toolbar clearfix">
              <form class="pull-right search-bar" method="get" action="" role="form">
                <div class="input-group">
                  <div class="input-group-btn">
                    <input type="hidden" name="search" id="search" value="renname">
                    <button class="btn btn-default dropdown-toggle" id="search-btn" data-toggle="dropdown" type="button" aria-haspopup="true" aria-expanded="false">
                      姓名 <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu">
                      <li> <a tabindex="-1" href="javascript:void(0)" data-field="renname">姓名</a> </li>
                      <li> <a tabindex="-1" href="javascript:void(0)" data-field="proxy_acc">账号</a> </li>
                    </ul>
                  </div>
                  <input type="text" class="form-control" value="" name="keyword" placeholder="请输入查询信息">
                </div>
              </form>
              <div class="toolbar-btn-action">
               
              </div>
            </div>
            <div class="card-body">
              <div class="table-responsive">
                <form name="form1" id="form1" method="post" action="controller/deleteall.php">
                  <table class="table table-bordered">
                      <?php
                        include_once("../untils/conn.php");
                        mysqli_query($con, "set names utf8");
                        if ($con) {
                          if ($db) {
                            // 获取搜索关键词和字段
                            $keyword = $_GET['keyword'];
                            $field = $_GET['search'];
                        
                            // 构建查询语句
                            $sql = "SELECT * FROM rename_table";
                            if ($keyword != "") {
                              $sql .= " WHERE $field LIKE '%$keyword%'";
                            }
                        
                            // 获取数据总行数
                            $data = mysqli_query($con, $sql);
                            $maxrows = mysqli_num_rows($data);
                        
                            // 计算总页数
                            $page_size = 10; // 每页显示数
                            if ($maxrows % $page_size == 0) {
                              $maxpage = (int)($maxrows / $page_size);
                            } else {
                              $maxpage = (int)($maxrows / $page_size) + 1;
                            }
                        
                            // 获取当前页
                            if (isset($_GET['curpage'])) {
                              $page = $_GET['curpage'];
                            } else {
                              $page = 1;
                            }
                        
                            // 分段取出数据
                            $start = $page_size * ($page - 1);
                            $get_sql = "$sql ORDER BY id DESC LIMIT $start, $page_size";
                        
                            // 获取数据显示
                            $data = mysqli_query($con, $get_sql);
                        ?>
                        <thead>
                          <tr>
                            <th>ID</th>
                            <th>账号</th>
                            <th>真实姓名</th>
                            <th>身份证号</th>
                            <th>手机号</th>
                            <th>申请时间</th>
                            <th>审核时间</th>
                            <th>状态</th>
                            <th>说明</th>
                            
                            <th>操作</th>
                          </tr>
                        </thead>
                        <tbody>
                        <?php
                         $id = null; // 定义变量
                         $proxy_acc = null ;
                         $rename = null;
                         $reuid = null;
                         $phone = null ;
                        while ($row = mysqli_fetch_array($data)) {
                         $id = $row["id"]; // 将$row['id']赋值给$id变量
                         $proxy_acc = $row["proxy_acc"];
                         $rename = $row["rename"];
                         $reuid = $row["reuid"];
                         $phone = $row["phone"] ;
                        ?>
                            <tr>
                                <td style="width:3%;">
                                    <?php echo $row["id"] ?>
                                </td>
                                <td style="width:5%;">
                                    <?php echo $row["proxy_acc"] ?>
                                </td>
                                <td style="width:5%;">
                                    <?php echo $row["rename"] ?>
                                </td>
                                
                                 <td style="width:5%;">
                                    <?php echo $row["reuid"] ?>
                                </td>
                                
                                <td style="width:5%;">
                                    <?php echo $row["phone"] ?>
                                </td>
                                
                                <td style="width:6%;">
                                    <?php echo $date = date('Y-m-d H:i:s', $row["sutime"]); ?>
                                </td>
                                <td style="width:6%;">
                                    <?php echo $date = date('Y-m-d H:i:s', $row["uptime"]); ?>
                                </td>

                                <td style="width:5%;">
                                    <?php 
                                        if($row["status"] == 0){
                                            echo "待审核";
                                        }elseif($row["status"] == 1){
                                            echo "已审核";
                                        }elseif($row["status"] == 2){
                                            echo "审核失败";
                                        }
                                    ?>
                                </td>
                                
                                   <td style="width:6%;">
                                    <?php echo $row["notes"] ?>
                                </td>
                                
                                <td style="width:15%;">
                                    <?php 
                                        switch($row["status"]) {
                                            case 0:
                                                echo '<button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#banModal" data-whatever="@mdo">操作审核</button>';
                                                break;
                                            case 1:
                                                echo '<span class="btn btn-warning btn-sm">已审核</span>';
                                                break;
                                            case 2:
                                                echo '<span class="btn btn-info btn-sm">审核失败</span>';
                                                break;
                                            default:
                                                echo '<span class="btn btn-danger btn-sm">状态错误</span>';
                                                break;
                                        }
                                    ?>
                                </td>
                            </tr>
                        <?php
                        }
                        ?>
                    </tbody>
                        <tfoot>
                          <tr>
                            <td colspan="12" style="text-align: right;">
                          <?php
                          echo "<p>共 $maxpage 页&nbsp;&nbsp;";
                          echo "每页 $page_size 项&nbsp;&nbsp;";
                          //设置上一页
                          if ($page > 1) {
                            $prepage = $page - 1;
                            echo "<a href='?curpage=$prepage'>上一页</a>&nbsp;&nbsp;";
                          }
                          //设置下一页
                          if ($page < $maxpage) {
                            $nextpage = $page + 1;
                            echo "<a href='?curpage=$nextpage'>下一页</a>&nbsp;&nbsp;";
                          }
                          echo "&nbsp;&nbsp;第 $page 页</p>";
                        }
                      }
                          ?>
                            </td>
                          </tr>
                        </tfoot>
                  </table>
                </form>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    </div>
                           <!--这是操作审核-->
                             <div class="modal fade" id="banModal" tabindex="-1" role="dialog" aria-labelledby="banModalLabel">
                              <div class="modal-dialog" role="document">
                                <div class="modal-content">
                                  <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                    <h4 class="modal-title" id="banModalLabel">操作审核</h4>
                                  </div>
                                  <div class="modal-body">
                                    <form action="controller/Dorename.php" method="POST">
                                        <div class="form-group">
                                        <label for="proxy_type">审核状态</label>
                                        <div >
                                          <select class="form-control" id="status" name="status" size="1">
                                            <option value="1">审核通过</option>
                                            <option value="2">审核失败</option>
                                          </select>
                                        </div>
                                      </div>
                                      <div class="form-group">
                                        <label for="message-text" class="control-label">失败说明：</label>
                                        <textarea class="form-control" id="message-text" name="notes" placeholder="审核通过时，可为空，审核失败时请输入原因，代理在后台提示！" ></textarea>
                                      </div>
                                      <!--id-->
                                      <input type="hidden" name="id" value="<?php echo $id ?>">
                                      <input type="hidden" name="proxy_acc" value="<?php echo $proxy_acc ?>">
                                      <input type="hidden" name="rename" value="<?php echo $rename ?>">
                                      <input type="hidden" name="reuid" value="<?php echo $reuid ?>">
                                      <input type="hidden" name="phone" value="<?php echo $phone ?>">
                                    
                                  </div>
                                  <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                    <button type="submit" class="btn btn-primary">确认提交</button>
                                  </div>
                                  </form>
                                </div>
                              </div>
                            </div>
                            <!--这里操作结束了-->
  </main>
   <script src="../merchant/assets/js/jquery.min.js"></script>
                <script>
                  $(document).ready(function() {
                    $('.dropdown-menu a').click(function(e) {
                      e.preventDefault();
                      var field = $(this).data('field');
                      var buttonText = $(this).text();
                      $('#search').val(field);
                      $('#search-btn').html(buttonText + ' <span class="caret"></span>');
                    });
                  });
                </script> 
  <!--End 页面主要内容-->
  <?php require_once('common/footer.php'); ?>
<?php
} else {
  echo "<script>alert('您尚未登录，没有权限访问该页面');location.href='login.php';</script>";
}
